//
// Created by songpingwang on 25-7-6.
//

#include "../thirdparty/ctre-unicode.hpp"
#include <iostream>
#include <string>
#include <vector>

namespace Patterns {
    constexpr auto invoice = ctll::fixed_string{
        u8R"(票据代码:_(\d+)_票据号码:_(\d+)_交款人统一社会信用代码:_([0-9*]+)_校验码:_(\d+)_交款人:_([\p{script=Han}]+)_开票日期:_(\d{4}-\d{1,2}-\d{1,2})_项目编码)"
    };
}


int test() {
    const std::vector<std::string> test_cases = {
        u8"票据代码:_12345_票据号码:_67890_交款人统一社会信用代码:_91234567890*_校验码:_5555_交款人:_张三_开票日期:_2023-01-01_项目编码",
        u8"票据代码:_54321_票据号码:_09876_交款人统一社会信用代码:_98765 * 4321*_校验码:_7777_交款人:_李四_开票日期:_2023-12-31_项目编码",
        u8"票据代码:12345_票据号码:67890_交款人统一社会信用代码:91234567890*_校验码:5555_交款人:张三_开票日期:2023-01-01"
    };

    for (const auto& test : test_cases) {
        std::cout << "\n测试字符串: " << test << "\n";
        if (auto match = ctre::match<Patterns::invoice>(test)) {
            std::cout << "  票据代码: " << match.get<1>().to_string() << "\n";
            std::cout << "  票据号码: " << match.get<2>().to_string() << "\n";
            std::cout << "  统一社会信用代码: " << match.get<3>().to_string() << "\n";
            std::cout << "  校验码: " << match.get<4>().to_string() << "\n";
            std::cout << "  交款人: " << match.get<5>().to_string() << "\n";
            std::cout << "  开票日期: " << match.get<6>().to_string() << "\n";
        } else {
            std::cout << "  匹配失败!\n";
        }
    }

    return 0;
}

// int test_chinese_multi_groups() {
//     const std::string text = "helle 正则表达式：测试结果test text is null，日期：2025-07-07";
//
//     constexpr auto pattern = ctll::fixed_string{u8"(正则表达式[:：]\\s*([\x{4e00}-\x{9fa5}]+).*?日期[:：]\\s*(\\d{4}-\\d{2}-\\d{2}))"};
//     const RE2 pattern2(R"(正则表达式[:：]\s*([\x{4e00}-\x{9fa5}]+).*?日期[:：]\s*(\d{4}-\d{2}-\d{2}))");
//     if (!pattern2.ok()) {
//         std::cerr << "Regex compilation failed: " << pattern2.error() << std::endl;
//         return 1;
//     }
//
//     // RE2::PartialMatch 的参数顺序(文本, 正则对象, &捕获组1, &捕获组2, ...)
//     std::string result_text, date_str;
//     if (RE2::PartialMatch(text, pattern2, &result_text, &date_str)) {
//         // 期望输出 "Matched: 测试结果 日期: 2025-07-07"
//         std::cout << "Matched: " << result_text << " 日期: " << date_str << std::endl;
//     } else {
//         std::cout << "Match failed!" << std::endl;
//     }
//     return 0;
// }


int main() {
    // test_chinese_multi_groups();
    test();
    return 0;

}